<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #box{
            width: 300px;
            height: 300px;
            background-color: #555;
            color: #fff;
        }
    </style>
</head>
<body>
    
    <div id="box">
        hello
    </div>

    <script>
        document.body.onclick = function(){
            console.log("close");
        }

        document.getElementById('box').onclick = function(e){
            e.stopPropagation();
        }
    </script>
</body>
</html>